home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / mach / sun4c.md / compare.c < prev    next >
C/C++ Source or Header  |  1989-08-17  |  2KB  |  75 lines

  1. #ifdef sccsid
  2. static char     sccsid[] = "@(#)compare.c 1.4 88/02/08 Copyr 1986 Sun Micro";
  3. #endif
  4.  
  5. /*
  6.  * Copyright (c) 1986 by Sun Microsystems, Inc. 
  7.  */
  8.  
  9. /*
  10.  * This whole file refuses to lint.
  11.  */
  12. #ifndef lint
  13.  
  14. #include <sun4/fpu/fpu_simulator.h>
  15. #include <sun4/fpu/globals.h>
  16.  
  17. enum fcc_type
  18. _fp_compare(px, py, strict)
  19.     unpacked       *px, *py;
  20.     int             strict;    /* 0 if quiet NaN unexceptional, 1 if
  21.                  * exceptional */
  22.  
  23. {
  24.     enum fcc_type   cc;
  25.  
  26.     if ((px->fpclass == fp_quiet) || (py->fpclass == fp_quiet) ||
  27.         (px->fpclass == fp_signaling) || (py->fpclass == fp_signaling)) {    /* NaN */
  28.         if (strict)
  29.             fpu_set_exception(fp_invalid);
  30.         cc = fcc_unordered;
  31.     } else if ((px->fpclass == fp_zero) && (py->fpclass == fp_zero))
  32.         cc = fcc_equal;
  33.     /* both zeros */
  34.     else if (px->sign < py->sign)
  35.         cc = fcc_greater;
  36.     else if (px->sign > py->sign)
  37.         cc = fcc_less;
  38.     else {            /* signs the same, compute magnitude cc */
  39.         if ((int) px->fpclass > (int) py->fpclass)
  40.             cc = fcc_greater;
  41.         else if ((int) px->fpclass < (int) py->fpclass)
  42.             cc = fcc_less;
  43.         else
  44.          /* same classes */ if (px->fpclass == fp_infinity)
  45.             cc = fcc_equal;    /* same infinity */
  46.         else if (px->exponent > py->exponent)
  47.             cc = fcc_greater;
  48.         else if (px->exponent < py->exponent)
  49.             cc = fcc_less;
  50.         else
  51.          /* equal exponents */ if (px->significand[0] > py->significand[0])
  52.             cc = fcc_greater;
  53.         else if (px->significand[0] < py->significand[0])
  54.             cc = fcc_less;
  55.         else
  56.          /* equal upper significands */ if (px->significand[1] > py->significand[1])
  57.             cc = fcc_greater;
  58.         else if (px->significand[1] < py->significand[1])
  59.             cc = fcc_less;
  60.         else
  61.             cc = fcc_equal;
  62.         if (px->sign)
  63.             switch (cc) {    /* negative numbers */
  64.             case fcc_less:
  65.                 cc = fcc_greater;
  66.                 break;
  67.             case fcc_greater:
  68.                 cc = fcc_less;
  69.                 break;
  70.             }
  71.     }
  72.     return (cc);
  73. }
  74. #endif /* lint */
  75.